package part2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public aspect Sensoring {
	
	//TODO: Case insensitivity
	
	pointcut callsToPrintlnStatements(String s):
		call(void java.io.PrintStream.println(String)) && args(s) && !within(Sensoring);
	
	void around(String s): 
		callsToPrintlnStatements(s) 
	{
		List<String> offensiveWords = OffensiveWords.getOffensiveWords();
		String toPrint = s;
		for(String offensiveWord : offensiveWords){
			if (s.contains(offensiveWord)){
				int substringFirstIndex = s.indexOf(offensiveWord);
				int offensiveWordLength = offensiveWord.toCharArray().length;
				String sensorString = "";
				for(int i = 0; i < offensiveWordLength; i++){
					sensorString += "#";
				}
				toPrint = s.replace(offensiveWord, sensorString);
			}
		}
		
		System.out.println(toPrint);
	}
	
	pointcut callsToPrintStatements(String s):
		call(void java.io.PrintStream.print(String)) && args(s) && !within(Sensoring);
	
	void around(String s): 
		callsToPrintStatements(s) 
	{
		List<String> offensiveWords = OffensiveWords.getOffensiveWords();
		String toPrint = s;
		for(String offensiveWord : offensiveWords){
			if (s.contains(offensiveWord)){
				int substringFirstIndex = s.indexOf(offensiveWord);
				int offensiveWordLength = offensiveWord.toCharArray().length;
				String sensorString = "";
				for(int i = 0; i < offensiveWordLength; i++){
					sensorString += "#";
				}
				toPrint = s.replace(offensiveWord, sensorString);
			}
		}
		
		System.out.print(toPrint);
	}
	
	
}
